Skip to content

refactor: add custom properties for color variants & fix: center slider vertically across size variants#6

Merged
scardanzan merged 3 commits into
masterfrom
issue-3-issue-5
May 14, 2026
Merged

refactor: add custom properties for color variants & fix: center slider vertically across size variants#6
scardanzan merged 3 commits into
masterfrom
issue-3-issue-5

Conversation

@paodb
Copy link
Copy Markdown
Member

@paodb paodb commented May 13, 2026

Summary of PR contents:

Issue #3:

The Base theme in Vaadin is intentionally colorless — it's a structural-only foundation meant for developers who want to build their own visual design from scratch. When a user picks Base theme, they're explicitly opting out of preset colors. Silently injecting hardcoded fallback colors would work against that decision.

Instead, the component now declares --toggle-button-* tokens in :host that default to Lumo/Aura variables. This makes the color API explicit: on Lumo/Aura the tokens resolve automatically; on Base theme, variants render without color by design, and users fix it with a single CSS variable like --toggle-button-success-color: green rather than having to know which internal theme variable to override.

Issue #5:

A fix to enter slider vertically across size variants. The 1px dashed readonly border reduced inner height by 2px but slider top was hardcoded to 1px for all sizes. Changed base top/left to 2px and added overrides: 1px for small, 3px for large. Selectors also apply correctly to longswipe variants.

New demo view:

New ToggleButtonReadOnlyDemo tab to demostrate readonly behavior when combined with the different variants. Covers sizes, long-swipe, and color variants,each in checked and unchecked states. It's a visual regression coverage for both fixes above.

Tested locally in for both Vaadin 24 & Vaadin 25 profiles.

Close #3 & Close #5

Summary by CodeRabbit

  • Style

    • Enhanced toggle button styling with centralized theme colors and improved visual consistency across active, checked, and readonly states.
  • Documentation

    • Added comprehensive demo showcasing read-only toggle button functionality with multiple size and style variants.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bc42ec05-9026-472e-8438-fcb5ca2e0e2c

📥 Commits

Reviewing files that changed from the base of the PR and between 919d1bc and d926fc6.

📒 Files selected for processing (3)
  • src/main/resources/META-INF/resources/frontend/fc-toggle-button.js
  • src/test/java/com/flowingcode/vaadin/addons/togglebutton/ToggleButtonDemoView.java
  • src/test/java/com/flowingcode/vaadin/addons/togglebutton/ToggleButtonReadOnlyDemo.java

Walkthrough

This PR centralizes toggle button theme colors into CSS custom properties (--toggle-button-*) with theme-variable fallbacks, applies them to active labels and checked switches, fixes readonly slider vertical alignment for all size variants, and adds a new readonly demo view to showcase the updated styling.

Changes

Theme Colors and Readonly Slider Fixes

Layer / File(s) Summary
CSS custom properties and base slider styling
src/main/resources/META-INF/resources/frontend/fc-toggle-button.js
New --toggle-button-* CSS variables map theme colors (primary/success/error/warning/contrast) with fallbacks; base slider styling updated with refined contrast and box-shadow values.
Active label and checked switch variant colors
src/main/resources/META-INF/resources/frontend/fc-toggle-button.js
Active label text and checked switch backgrounds now use the new --toggle-button-* variables instead of direct --lumo-* and --aura-* tokens for all theme variants.
Readonly slider positioning and variant borders
src/main/resources/META-INF/resources/frontend/fc-toggle-button.js
Readonly slider top offset corrected for default (2px) and large (3px) sizes to align properly with the 1px dashed border; readonly + checked variant borders use --toggle-button-*-color in color-mix() expressions.
Readonly demo view and registration
src/test/java/com/flowingcode/vaadin/addons/togglebutton/ToggleButtonReadOnlyDemo.java, src/test/java/com/flowingcode/vaadin/addons/togglebutton/ToggleButtonDemoView.java
New routed demo page displays read-only toggle buttons grouped by size, long-swipe behavior, and color variants; demo is registered in the demo view constructor.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • FlowingCode/ToggleButton#4: Both PRs modify readonly and checked styling in the same CSS file, with overlapping rule-level changes for toggle/slider appearance and variant border behavior.

Suggested reviewers

  • javier-godoy
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects both main changes: centralizing color variants into CSS custom properties and fixing vertical slider centering across size variants.
Linked Issues check ✅ Passed Changes address both Issue #3 (CSS custom properties for color variants on Base theme) and Issue #5 (readonly slider vertical centering) with corresponding test demo coverage.
Out of Scope Changes check ✅ Passed All changes directly support the linked issues: CSS refactoring for Issue #3, slider alignment for Issue #5, and demo view for visual regression testing.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-3-issue-5

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@paodb paodb marked this pull request as ready for review May 13, 2026 18:58
@paodb paodb requested review from javier-godoy and scardanzan May 13, 2026 18:58
Copy link
Copy Markdown
Member

@scardanzan scardanzan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@scardanzan scardanzan merged commit 7464324 into master May 14, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from To Do to Pending release in Flowing Code Addons May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pending release

2 participants